import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig(({ mode }) => {
    // 1. 主动加载环境变量
    const env = loadEnv(mode, process.cwd());
    return {
        plugins: [
            vue(),
            AutoImport({
                imports: [
                    'vue',
                    'vue-router',
                    '@vueuse/core',
                    'pinia',
                    {
                        'element-plus': [
                            'ElMessage',
                            'ElMessageBox',
                            'ElNotification',
                        ],
                    },
                ],
                eslintrc: {
                    enabled: true,
                    filepath: './.eslintrc-auto-import.json',
                    globalsPropValue: true,
                },
                resolvers: [
                    ElementPlusResolver(),
                ],
                dts: 'src/types/auto-imports.d.ts',
                vueTemplate: true,
            })
        ],
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src'),
            },
        },
        server: {
            proxy: {
                '/api': {
                    target: 'http://127.0.0.1:8081',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, '')
                }
            }
        },
      
    };
});